//package com.jh.fcsm.common.aspect;
//
//import com.jh.fcsm.common.annotation.TargetDataSource;
//import com.jh.fcsm.config.DataSourceManagement;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.reflect.MethodSignature;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Component;
//
//import java.lang.reflect.Method;
//
//@Component
//@Aspect
//public class TargetDataSourceAop {
//    private static final Logger logger = LoggerFactory.getLogger(TargetDataSourceAop.class);
//
//    @Around("@within(TargetDataSource) || @annotation(TargetDataSource)")
//    public Object beforeNoticeUpdateDataSource(ProceedingJoinPoint joinPoint) throws Throwable {
//        TargetDataSource annotation = null;
//        Class<? extends Object> target = joinPoint.getTarget().getClass();
//        if (target.isAnnotationPresent(TargetDataSource.class)) {
//            // 判断类上是否标注着注解
//            annotation = target.getAnnotation(TargetDataSource.class);
//            logger.info("类上标注了注解");
//        } else {
//            Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
//            if (method.isAnnotationPresent(TargetDataSource.class)) {
//                //判断方法上是否标注着注解，如果类和方法上都没有标注，则报错
//                annotation = method.getAnnotation(TargetDataSource.class);
//                logger.info("方法上标注了注解");
//            } else {
//                throw new RuntimeException("@TargetDataSource注解只能用于类或者方法上, 错误出现在:[" + target.toString() + " " + method.toString() + "];");
//            }
//        }
//        // 切换数据源
//        DataSourceManagement.flag.set(annotation.value().name());
//        return joinPoint.proceed();
//    }
//}
//
//
